#pragma once
#include <queue>
#include "Mutex.h"
#include "QueueElement.h"

using namespace std;

template <typename T>
class QueueManager
{
public:
	QueueManager(void)
	{
		myQueue = queue<T*>();
	};
	~QueueManager(void){};

	bool push(T* data)
	{
		Thread_Mutex_Guard mutex(myMutex);

		if(data != NULL)
		{
			myQueue.push(data);
			return true;
		}

		return false;
	}

	T* popFront()
	{
		Thread_Mutex_Guard mutex(myMutex);

		T* latestElement = NULL;

		if(myQueue.size() != 0)
		{
			latestElement = myQueue.front();
			myQueue.pop();
		}

		return latestElement;
	}

	unsigned int size() 
	{
		Thread_Mutex_Guard mutex(myMutex);
		return myQueue.size();
	}

	bool empty()
	{
		Thread_Mutex_Guard mutex(myMutex);

		if(myQueue.size != 0)
		{
			myQueue.empty();
		}

		if(myQueue.size() == 0)
			return true;

		return false;
	}

private:
	queue<T*> myQueue;
	Thread_Mutex myMutex;
};

